using System;
using System.Collections.Generic;
using BanZuiCloudControlAgent.Core.Tasks.Enums;

namespace BanZuiCloudControlAgent.Core.Tasks.Models
{
    /// <summary>
    /// 任务结果类，表示任务执行的结果
    /// </summary>
    public class TaskResult
    {
        /// <summary>
        /// 任务状态
        /// </summary>
        public TaskState Status { get; set; }
        
        /// <summary>
        /// 结果消息
        /// </summary>
        public string Message { get; set; }
        
        /// <summary>
        /// 错误消息
        /// </summary>
        public string ErrorMessage { get; set; }
        
        /// <summary>
        /// 异常信息
        /// </summary>
        public Exception Exception { get; set; }
        
        /// <summary>
        /// 结果数据
        /// </summary>
        public object Data { get; set; }
        
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool IsSuccess => Status == TaskState.Completed;
        
        /// <summary>
        /// 是否失败
        /// </summary>
        public bool IsFailure => Status == TaskState.Failed;
        
        /// <summary>
        /// 是否取消
        /// </summary>
        public bool IsCanceled => Status == TaskState.Canceled;
        
        /// <summary>
        /// 是否需要重试
        /// </summary>
        public bool IsRetry => Status == TaskState.Retry;
        
        /// <summary>
        /// 构造函数
        /// </summary>
        public TaskResult()
        {
            Status = TaskState.Pending;
        }
        
        /// <summary>
        /// 创建成功结果
        /// </summary>
        /// <param name="message">成功消息</param>
        /// <param name="data">结果数据</param>
        /// <returns>任务结果</returns>
        public static TaskResult Success(string message = "任务执行成功", object data = null)
        {
            return new TaskResult
            {
                Status = TaskState.Completed,
                Message = message,
                Data = data
            };
        }
        
        /// <summary>
        /// 创建失败结果
        /// </summary>
        /// <param name="errorMessage">错误消息</param>
        /// <param name="exception">异常信息</param>
        /// <param name="data">结果数据</param>
        /// <returns>任务结果</returns>
        public static TaskResult Failure(string errorMessage, Exception exception = null, object data = null)
        {
            return new TaskResult
            {
                Status = TaskState.Failed,
                ErrorMessage = errorMessage,
                Exception = exception,
                Data = data
            };
        }
        
        /// <summary>
        /// 创建取消结果
        /// </summary>
        /// <param name="message">取消消息</param>
        /// <param name="data">结果数据</param>
        /// <returns>任务结果</returns>
        public static TaskResult Canceled(string message = "任务已取消", object data = null)
        {
            return new TaskResult
            {
                Status = TaskState.Canceled,
                Message = message,
                Data = data
            };
        }
        
        /// <summary>
        /// 创建重试结果
        /// </summary>
        /// <param name="message">重试消息</param>
        /// <param name="data">结果数据</param>
        /// <returns>任务结果</returns>
        public static TaskResult Retry(string message = "任务需要重试", object data = null)
        {
            return new TaskResult
            {
                Status = TaskState.Retry,
                Message = message,
                Data = data
            };
        }
    }
} 